package algorithms;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int j = 0; j < n; j++) {
            arr[j] = sc.nextInt();
        }
        quickSort(arr, 0, arr.length - 1);
        int near = Integer.MAX_VALUE;
        for (int i = arr.length - 1; i >= 1; i--) {
            near = Math.min(near, arr[i] - arr[i - 1]);
        }
        System.out.println(near);
    }

    private static void quickSort(int[] arr, int start, int end) {
        if (start >= end) {
            return;
        }
        int pivotIndex = partitionThenReturnPivotIndex(arr, start, end);
        quickSort(arr, start, pivotIndex - 1);
        quickSort(arr, pivotIndex + 1, end);
    }

    private static int partitionThenReturnPivotIndex(int[] a, int start, int end) {
        int i = start - 1;
        int j = start;
        int pivot = a[end];
        for (; j <= end - 1; j++) {
            if (a[j] <= pivot) {
                //这个加1的操作，就是扩展区域的过程
                i = i + 1;
                exchange(a, i, j);
            }
        }
        exchange(a, i + 1, end);
        return i + 1;
    }

    private static void exchange(int[] a, int i, int j) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}
